from __future__ import annotations

from dataclasses import dataclass


@dataclass
class SeepageCheck:
    gradient: float
    critical_gradient: float
    safety_factor: float
    note: str


def check_piping_stability(head_loss_m: float, seepage_length_m: float, saturated_unit_weight_kN_m3: float = 20.0, water_unit_weight_kN_m3: float = 9.81) -> SeepageCheck:
    """管涌/流砂验算：i = Δh/L；i_cr ≈ (γ_sat - γ_w)/γ_w。Fs=i_cr/i。"""

    i = head_loss_m / max(1e-6, seepage_length_m)
    i_cr = max(0.1, (saturated_unit_weight_kN_m3 - water_unit_weight_kN_m3) / max(1e-6, water_unit_weight_kN_m3))
    Fs = i_cr / max(1e-6, i)
    return SeepageCheck(gradient=i, critical_gradient=i_cr, safety_factor=Fs, note="Fs≥1.5为宜")


